Skip to content

Solution - #3914

Open
Augustwise wants to merge 2 commits into
mate-academy:masterfrom
Augustwise:develop
Open

Solution#3914
Augustwise wants to merge 2 commits into
mate-academy:masterfrom
Augustwise:develop

Conversation

@Augustwise

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

The implementation is very close, but there is a critical blocker: the requirement to update Animal.alive using Array.prototype.filter to remove dead animals (those with health <= 0) is not met. Instead, the code uses indexOf and splice inside the die() method, and checks for presence before removal. This directly violates the explicit checklist item and technical constraints for this task.

What needs fixing:

  • Refactor the logic so that after any health change (especially after a bite), Animal.alive is reassigned using filter to exclude animals with health <= 0.
  • Remove all uses of indexOf and splice for this purpose, and do not check for presence before filtering.

For example, you might update the array like this:

Animal.alive = Animal.alive.filter(animal => animal.health > 0);

Once you make this change, your code will fully comply with the requirements. You did a great job with the rest of the class structure and method logic—just this one technical detail needs to be addressed. Keep going, you're almost there!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/herbivoresAndCarnivores.js Outdated
Comment on lines +13 to +16
const index = Animal.alive.indexOf(this);

if (index > -1) {
Animal.alive.splice(index, 1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item: "The Animal.alive array must be updated using Array.prototype.filter to remove dead animals (those with health <= 0)." The current implementation uses indexOf and splice in the die() method, which is not allowed. You must use filter to update Animal.alive after an animal's health drops to 0 or below.

@Augustwise

Augustwise commented Aug 15, 2025

Copy link
Copy Markdown
Author

I corrected the solution, but the original requirements (readme.md file) did not specify that Array.prototype.filter should be used. I consider this to be an error on your part, as I only learned about it from you after the commit.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

All core requirements and checklist items are fully met. Your implementation of the Animal, Herbivore, and Carnivore classes is correct, uses ES6 class syntax, and handles all specified behaviors (including hiding, biting, and alive tracking) exactly as described. The use of Array.prototype.filter for managing the Animal.alive array is spot-on, and all technical constraints are respected. Great job—your code is clear, maintainable, and ready for the next steps!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants